package com.huxiu;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.Request;
import com.android.volley.Response;
import com.huxiu.net.GsonRequest;
import com.huxiu.net.NetworkConstants;
import com.huxiu.net.responses.BaseResponse;
import com.huxiu.utils.Utils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.umeng.analytics.MobclickAgent;

import java.util.LinkedHashMap;
import java.util.Map;

public class FanKuiActivity extends BaseActivity {


    @ViewInject(R.id.edit_neirong)
    private EditText neirong;

    @ViewInject(R.id.edit_lianxi)
    private EditText lianxifangshi;

    @ViewInject(R.id.text_sure)
    private TextView text_sure;

    @ViewInject(R.id.text_exit)
    private TextView text_exit;

    @ViewInject(R.id.back)
    private ImageView back;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fan_kui);
        ViewUtils.inject(this);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        text_sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (inputValid()) {
                    tijiaoFankui();
                }
            }
        });
        text_exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

    }

    private void tijiaoFankui() {
        String url = NetworkConstants.FEEDBACK_URL;
        Map<String, String> params = new LinkedHashMap<>();
        params.put("content", neirong.getText().toString());
        params.put("contact", lianxifangshi.getText().toString());
        GsonRequest<BaseResponse> request = new GsonRequest<>(url, Request.Method.POST,
                BaseResponse.class, false, params, new Response.Listener<BaseResponse>() {
            @Override
            public void onResponse(BaseResponse response) {
                if (response.isSuccess()) {
                    Utils.showToast("反馈已提交");
                    finish();
                } else {
                    Utils.showToast(response.error.message);
                }
            }
        }, mErrorListener);
        mQueue.add(request);
    }

    //下面是登录相关接口
    private boolean inputValid() {
        if (TextUtils.isEmpty(neirong.getText().toString())) {
            Utils.showToast(R.string.feedback_neiyong);
            return false;
        }
        return true;
    }


    @Override
    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart("SplashScreen");
        MobclickAgent.onResume(this);
    }
    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd("SplashScreen");
        MobclickAgent.onPause(this);
    }

}
